public class test5 {
    public static void main(String[] args) {
        System.out.println(backspaceCompare("y#fo##f", "y#f#o##f"));
    }
    public static boolean backspaceCompare(String s, String t) {
        StringBuffer ret1 = new StringBuffer();
        StringBuffer ret2 = new StringBuffer();
        char[] arr1 = s.toCharArray();
        char[] arr2 = t.toCharArray();

        for(char ch : arr1){
            if(ch=='#'){
                if(ret1.length()>0 ){
                    ret1.deleteCharAt(ret1.length()-1);
                }else{

                }
            }else{
                ret1.append(ch);
            }
        }

        for(char ch : arr2){
            if(ch=='#'){
                if(ret2.length()>0 ){
                    ret2.deleteCharAt(ret2.length()-1);
                }else{

                }
            }else{
                ret2.append(ch);
            }
        }
//        System.out.println(ret1.toString());
//        System.out.println(ret2.toString());

        return ret1.toString().equals(ret2.toString());

    }
}
